package com.zbkj.crmeb.store.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zbkj.crmeb.store.dao.ChannelFreeShippingActivityProductDao;
import com.zbkj.crmeb.store.model.ChannelFreeShippingActivityProduct;
import com.zbkj.crmeb.store.service.ChannelFreeShippingActivityProductService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class ChannelFreeShippingActivityProductServiceImpl extends ServiceImpl<ChannelFreeShippingActivityProductDao, ChannelFreeShippingActivityProduct> implements ChannelFreeShippingActivityProductService {

    /**
     * 功能描述: 获取商品id
     * @Param: [activityIds]
     * @Return: java.util.List<java.lang.Integer>
     * @Author: wangzh
     * @Date: 2022/12/30 13:42
     */
    @Override
    public List<Integer> getProductIds(List<Integer> activityIds) {
        List<ChannelFreeShippingActivityProduct> list = this.list(Wrappers.<ChannelFreeShippingActivityProduct>lambdaQuery()
                .in(ChannelFreeShippingActivityProduct::getActivityId, activityIds));
        if (CollectionUtils.isEmpty(list)){
            return new ArrayList<>();
        }
        return list.stream().map(ChannelFreeShippingActivityProduct::getProductId).collect(Collectors.toList());
    }

    @Override
    public Boolean removeProductByActivityId(Integer activityId) {
        return this.remove(Wrappers.<ChannelFreeShippingActivityProduct>lambdaQuery()
                .eq(ChannelFreeShippingActivityProduct::getActivityId, activityId));
    }

    @Override
    public List<ChannelFreeShippingActivityProduct> getList(List<Integer> activityIds) {
        return this.list(Wrappers.<ChannelFreeShippingActivityProduct>lambdaQuery()
                .in(ChannelFreeShippingActivityProduct::getActivityId, activityIds));
    }

}
